#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using ll=long long;
const ll mod=998244353,INF=9e18;
__gnu_pbds::gp_hash_table<int,int> Mp;//nowb
struct Node
{
   int len,y;
}P[1000010];
ll b[500010],now,Ans,mAns,c,x,dlt,lnow;
int st[1000010],k[500010],top,m,n;
vector<int> a[500010];
bool cmp(Node A,Node B){return A.len<B.len;}
int main()
{
   freopen("list.in","r",stdin);
   freopen("list.out","w",stdout);
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
      scanf("%d",&k[i]);a[i].push_back(0);now+=k[i];
      for(int j=1,x;j<=k[i];j++)
      {
         scanf("%d",&x),a[i].push_back(x);Mp[x]++;
         if(j>1) P[++m]={x-a[i][j-1]+1,x};Ans++;
      }
   }scanf("%lld",&c);Ans*=c;sort(P+1,P+1+m,cmp);lnow=now;
   for(int i=1;i<=n;i++) scanf("%lld",&b[i]);x=1;
   for(auto to:Mp) Ans+=b[to.second]*to.second;
   mAns=Ans;st[top=1]=1;
   for(int i=1;i<=m;i++)
   {
      now--;Ans-=b[Mp[P[i].y]]*Mp[P[i].y];
      Mp[P[i].y]--;Ans+=b[Mp[P[i].y]]*Mp[P[i].y];
      if(P[i].len!=P[i+1].len)
      {
         dlt=P[i].len-x;Ans+=(dlt-1)*lnow*c;Ans+=now*c;
         if(Ans==mAns) st[++top]=P[i].len;
         else if(Ans<mAns) st[top=1]=P[i].len,mAns=Ans;
         x=P[i].len;lnow=now;
      }
   }
   printf("%lld %d\n",mAns,top);
   for(int i=1;i<=top;i++) printf("%d ",st[i]);
   return 0;
}